package cn.mumzone.pos.presenter;


import java.util.ArrayList;

import cn.mumzone.basic.mvp.AbsPresenter;
import cn.mumzone.basic.net.http.callback.ApiCallBack;
import cn.mumzone.basic.net.response.BaseResponse;
import cn.mumzone.pos.R;
import cn.mumzone.pos.model.DailyReportEntity;
import cn.mumzone.pos.model.DailySummaryEntity;
import cn.mumzone.pos.model.source.ReportRepository;
import cn.mumzone.pos.presenter.contract.DailyReportContract;
import cn.mumzone.pos.ui.adapter.ADA_DailySummary;

/**
 * Created by qiuzhenhuan on 2019/3/22.
 */

public class DailyReportPresenter extends AbsPresenter<DailyReportContract.View, ReportRepository> implements DailyReportContract.Presenter {

    @Override
    public void requestDailyReportByDate(String date) {
        mView.showLoadingDialog();
        ApiCallBack<DailyReportEntity> callBack = new ApiCallBack<DailyReportEntity>() {
            @Override
            public void onSuccess(DailyReportEntity entity) {
                ArrayList<DailySummaryEntity> summaryList = new ArrayList<>();

                summaryList.add(new DailySummaryEntity("应收金额",
                        entity.getActualAmount(), R.string.actual_amount, ADA_DailySummary.TYPE_TITLE));

                summaryList.add(new DailySummaryEntity("会员折扣",
                        entity.getDiscountAmount(), R.string.discount_amount, ADA_DailySummary.TYPE_BODY));

                summaryList.add(new DailySummaryEntity("议价优惠",
                        entity.getNegotiationAmount(), R.string.negotiation_amount, ADA_DailySummary.TYPE_BODY));

                summaryList.add(new DailySummaryEntity("赠送优惠",
                        entity.getPresentDiscount(), R.string.negotiation_amount, ADA_DailySummary.TYPE_BODY));

                summaryList.add(new DailySummaryEntity("商品折扣",
                        entity.getSaleDiscount(), R.string.sale_discount, ADA_DailySummary.TYPE_BODY));

                summaryList.add(new DailySummaryEntity("折扣活动",
                        entity.getActivityAmount(), R.string.activity_amount, ADA_DailySummary.TYPE_BODY));

                summaryList.add(new DailySummaryEntity("优惠券",
                        entity.getTicketAmount(), R.string.ticket_amount, ADA_DailySummary.TYPE_BODY));

                summaryList.add(new DailySummaryEntity("抹零",
                        entity.getLooseAmount(), R.string.loose_amount, ADA_DailySummary.TYPE_BODY));

//                summaryList.add(new DailySummaryEntity("积分抵现",
//                        entity.getIntegralAmount(), R.string.integral_amount, ADA_DailySummary.TYPE_BODY));

                summaryList.add(new DailySummaryEntity("= 实收金额",
                        entity.getReceivedAmount(), -1, ADA_DailySummary.TYPE_TITLE));

                summaryList.add(new DailySummaryEntity("退换货",
                        entity.getRefundAmount(), R.string.refund_amount, ADA_DailySummary.TYPE_BODY));

                summaryList.add(new DailySummaryEntity("= 总计金额",
                        entity.getAmount(), -1, ADA_DailySummary.TYPE_TITLE));
                mView.showDailyReport(entity,summaryList);
                mView.dismissLoadingDialog();

            }

            @Override
            public void onError(BaseResponse response) {
                mView.dismissLoadingDialog();
                mView.showError(response.getMsg());
            }
        };

        mRepo.getDailyReportByDate(date, callBack);
        addSubscrebe(callBack);
    }
}
